# this function translates countrycodes using ctrycodes.data.csv
library(data.table)
ctry.codes <- function(ocode, dcode, vector) {

	pth <- "~/Dropbox/Research/data/countrycodes/"
	lettercode <- c("iso3c", 
		"nicolCode", 
		"isoname", 
		"nber.country", 
		"iso2digitalpha", 
		"ctynameenglish", 
		"iso3ccomtrade")
	ctrycodes.data <- fread(paste(pth, "ctrycodes.data.csv", sep=""))

	od <- ctrycodes.data[ , c(ocode, dcode), with=FALSE]
	od <- na.omit(od, cols=ocode)
    od <- od[eval(call("!=", as.name(ocode), ""))] ## solution from https://stackoverflow.com/questions/27677283/evaluating-both-column-name-and-the-target-value-within-j-expression-within-d

	destiny_vector <- rep(NA, length(vector))

	for (i in 1:dim(od)[1]) {
		destiny_vector <- ifelse(vector == od[i, eval(as.name(ocode))] , 
			od[i, eval(as.name(dcode))], destiny_vector)
	}

	destiny_vector
}